﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CourseManager.Model.Data
{
	public class SCDAO
	{
		public static IEnumerable<Tab_SC> GetSCList(string studentId, string termId)
		{
			DBEntity ent = new DBEntity();
			return from sc in ent.Tab_SC
			       where sc.studentId.Equals(studentId) && sc.termId.Equals(termId)
			       select sc;
		}

		public static IEnumerable<Tab_SC> GetSCList(Tab_Course course)
		{
			DBEntity ent = new DBEntity();
			return from sc in ent.Tab_SC
				   where sc.courseId.Equals(course.courseId) && sc.termId.Equals(course.tId)
				   select sc;
		}


		public static Tab_SC GetSC(string studentId, string termId, 
			string courseId, string teacherId, string tId)
		{
			DBEntity ent = new DBEntity();
			return (from sc in ent.Tab_SC
			        where sc.studentId.Equals(studentId) && sc.termId.Equals(termId)
			              && sc.teacherId.Equals(teacherId) && sc.tId.Equals(tId)
			              && sc.courseId.Equals(courseId)
			        select sc).FirstOrDefault();
		}

		public static void RemoveSC(string studentId, string termId,
			string courseId, string teacherId, string tId)
		{
			DBEntity ent = new DBEntity();
			var item = (from sc in ent.Tab_SC
			            where sc.studentId.Equals(studentId) && sc.termId.Equals(termId)
			                  && sc.teacherId.Equals(teacherId) && sc.tId.Equals(tId)
			                  && sc.courseId.Equals(courseId)
			            select sc).FirstOrDefault();
			if(item != null)
			{
				ent.DeleteObject(item);
				ent.SaveChanges();
			}
		}
	}
}